﻿
//钩子函数
$(function () {
    generateDate();
});

//自动生成时间
function generateDate() {
    var n = new Date();
    var ss =  n.getFullYear() + (n.getMonth() + 1).toString().padStart(2, '0') +
        n.getDate().toString().padStart(2, '0') +
        n.getHours().toString().padStart(2, '0') +
        n.getMinutes().toString().padStart(2, '0') +
        n.getSeconds().toString().padStart(2, '0') + " ";
    var aa = "CP" + ss;
    var bb = "PC" + ss;
    $("#finishedProductNo").val(aa);
    $("#finishedProductBatch").val(bb);
}
layui.use(['layer', 'form', 'util'], function () {
    var layer = layui.layer;
    var $ = layui.jquery;
    var form = layui.form;
    var util = layui.util;

    form.on('submit(formDemo)', function (data) {
        var dto = data.field; // 获取表单字段值
        console.log(data);
        $.ajax({
            url: '/Warehouse/PostFinishedProductAdd',
            type: 'post',
            data: {
                dto: dto,
                token: localStorage.getItem("token")
            },
            success: function (res) {
                var res = JSON.parse(res)
                console.log(dto);
                console.log(res);
                if (res.code == 0) {
                    layer.alert("添加成功");
                    setTimeout(function () {
                        location.href = '/Warehouse/FinishedProductShow'
                    }, 2000);
                } else {
                    layer.alert("添加失败");
                }
            }
        });

        return false; // 阻止默认 form 跳转
    });
    // 对弹层中的表单进行初始化渲染
    form.render();
});